package solutionsdemo;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 黎鹤舞
 * Date: 2024-01-28
 * Time: 0:54
 */

import java.util.Scanner;

/**
 * 二叉树的遍历生成
 */
public class Ergodic {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextLine()) {
            String str = in.nextLine();
            TreeNode root = createTree(str);
            inOrder(root);
        }
    }
    //前序遍历生成二叉树
    public static int i = 0;
    public static TreeNode createTree(String str) {
        TreeNode root = null;
        char ch = str.charAt(i);
        //#表示空树
        if(ch == '#') {
            i++;
        }else {
            i++;
            //这里需要实例化TreeNode结点
            root = new TreeNode(ch);
            root.left = createTree(str);
            root.right = createTree(str);
        }
        return root;
    }

    public static void inOrder(TreeNode root){
        if(root == null) {
            return;
        }
        inOrder(root.left);
        System.out.print(root.val + " ");
        inOrder(root.right);
    }
}
